﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework;
using CNVP.JShop.UI;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin
{
    public partial class UserLeveEdit : AdminPage
    {
        BLL.CNVP_UserLevel bll = new BLL.CNVP_UserLevel();
        Model.CNVP_UserLevel model = new Model.CNVP_UserLevel();
        public int id = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 92)) return;//判断页面权限
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]) && Public.IsNumber(Request.QueryString["ID"]))
            {
                id = Convert.ToInt32(Request.QueryString["ID"]);
            }
            if (!IsPostBack)
            {
                if (id > 0)
                {
                    lbTitle.Text = " > 修改";
                    DataInfo(id);
                }
                else
                {
                    lbTitle.Text = " > 添加";
                }
            }

           
        }


        public void DataInfo(int id)
        {
            model = bll.GetSingle_CNVP_UserLevelById(id);
            if (model != null)
            {
                txtLevelName.Text = model.LevelName;
                txtDisCountPercent.Text = model.DisCountPercent.ToString();
                txtNeedPointsNum.Text = model.NeedPointsNum.ToString();
                rblIsAcquiesce.SelectedValue = model.IsAcquiesce.ToString();
                if (model.IsAcquiesce == 1)
                {
                    rblIsAcquiesce.Enabled = false;
                }
            }
        }

        protected void btUp_Click(object sender, EventArgs e)
        {
            try
            {
                model.LevelName = txtLevelName.Text.Trim();
                model.DisCountPercent = Convert.ToDecimal(txtDisCountPercent.Text.Trim());
                model.NeedPointsNum = int.Parse(txtNeedPointsNum.Text.Trim());
                if (rblIsAcquiesce.SelectedValue == "1")
                {
                    bll.Update_CNVP_PostAddressWhereOne();
                    model.IsAcquiesce = 1;
                }
                else
                {
                    model.IsAcquiesce = 0;
                }
                if (id > 0)
                {
                    model.ID = id;
                    bll.Update_CNVP_UserLevel(model);
                    BasePage.MessageBox("修改成功！", "UserLevelList.aspx?Page=" + Request.QueryString["Page"] + "");
                }
                else
                {
                    bll.Add_CNVP_UserLevel(model);
                    BasePage.MessageBox("添加成功！", "UserLevelList.aspx");
                }
            }
            catch
            {
                BasePage.MessageBox("失败！");
            }
        }

    }
}